package com.sengled.cloud.biz.union.mgt.dao.sys;


import com.sengled.cloud.biz.union.mgt.model.po.CurrentShop;
import com.sengled.cloud.biz.union.mgt.model.vo.CurrentModuleShopAccountVo;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
@Mapper
public interface CurrentShopDao {
    int deleteByPrimaryKey(Long id);

    int insert(CurrentShop record);

    @Insert(" insert into current_shop(module_id,user_account_id,current_shop_id,create_date) values(#{moduleId},#{userAccountId},#{currentShopId},#{createDate})")
    int insertSelective(CurrentShop record);

    CurrentShop selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(CurrentShop record);

    int updateByPrimaryKey(CurrentShop record);

    @Select("<script>"
            + "select m.id as moduleId,m.module_code as moduleCode,sa.shop_code as code,sa.shop_name as name,sa.id as id from module m,current_shop c,shop_account sa where c.module_id = m.id and c.user_account_id  = #{accountId}  and sa.id = c.current_shop_id and m.seal_mark = 0 and m.enable_mark = 1 and c.module_id in "
            + "<foreach item='item' index='index' collection='mainModuleIds' open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + "</script>")
    List<CurrentModuleShopAccountVo> selectCurrentModuleShopAccount(@Param("accountId") Long accountId,@Param("mainModuleIds") List<Long> mainModuleIds);

    @Select("select m.id as moduleId,m.module_code as moduleCode,sa.shop_code as code,sa.shop_name as name,sa.shop_id as id from module m,current_shop c,shop_account sa where c.module_id = m.id and c.user_account_id  = #{accountId}  and sa.shop_id = c.current_shop_id and m.seal_mark = 0 and m.enable_mark = 1")
    List<CurrentModuleShopAccountVo> selectCurrentShopByUserKey(@Param("accountId") Long accountId);

    @Select(" delete from current_shop where user_account_id = #{accountId} and module_id = #{moduleId} ")
    Integer deleteByModuleAndAccountKey(@Param("accountId") Long accountId,@Param("moduleId") Long moduleId);
    
    @Delete("delete from current_shop where current_shop_id = #{shopAccountId} and user_account_id = #{accountId}")
    int deleteByShopAccountId(@Param("shopAccountId") Long shopAccountId,@Param("accountId") Long accountId);
    
    @Select("select current_shop_id shopAccountId from current_shop where user_account_id  = #{accountId}")
    List<Long> selectCurrentShopIdByUserKey(@Param("accountId") Long accountId);
}